package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.service.TestMemberService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/checkmember")
public class TestMemberController {
    @Reference
    private TestMemberService testMemberService;
    @RequestMapping("/findBytelephone")
    public Result findmember(@RequestBody String coookie) {
        try {
            String[] split = coookie.split("=");
            Member findmember = testMemberService.findMember(split[0]);
            return new Result(true, MessageConstant.GET_USERNAME_SUCCESS, findmember);
        }catch (Exception e){
            return new Result(false,MessageConstant.QUERY_ORDER_FAIL);
        }
    }
    @RequestMapping("/editMember")
    public Result editMember(HttpServletRequest res, @RequestBody Member member){
        String id=null;
        for (Cookie cookie : res.getCookies()) {
            String value = cookie.getValue();
            id=value;
        }
        System.out.println(id);
        Member member1 = testMemberService.findMember(id);
        Integer id1 = member1.getId();
        member.setId(id1);
        testMemberService.editMember(member);
        return new Result(true, MessageConstant.TEST_MEMBER_SUCCESS);
    }

}
